package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Language;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The element FRBRlanguage is the metadata property containing a RFC4646
 * (three-letter code) of the main human language used in the content of this
 * expression
 * 
 * <pre>
 * <xsd:element name="FRBRlanguage">
 *   <xsd:complexType>
 * 		<xsd:complexContent>
 * 			<xsd:extension base="metaopt">
 * 				<xsd:attribute name="language" type="language" use="required"/>
 * 			</xsd:extension>
 * 		</xsd:complexContent>
 *   </xsd:complexType>
 * </xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class FRBRlanguage extends MetaOpt implements Language {
	
	public static final String ELEMENT = "FRBRlanguage";

	public static final String ATTRIBUTE_LANGUAGE = "language";
	
	private String _language;
	

	/**
	 * @see org.akomantoso.core.data.attribute.Language#getLanguage()
	 */
	public String getLanguage() {
		return _language;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Language#setLanguage(java.lang.String)
	 */
	public void setLanguage(String language) {
		_language = language;
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeMandatoryAttribute(out, ATTRIBUTE_LANGUAGE, _language, this);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_language = in.readAttribute(ATTRIBUTE_LANGUAGE);
		super.readExternal(in);
	}
	
}